//
//  UIBarButtonItem+Extensions.swift
//  weibo
//
//  Created by wenquan wang on 11/25/16.
//  Copyright © 2016 wenquan wang. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false){
        let btn : UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        //navigationItem.leftBarButtonItem = UIBarButtonItem(customView: btn)
        
        if isBack{
            let imgName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imgName), for: UIControlState(rawValue: 0))
            btn.setImage(UIImage(named: imgName + "_highlighted"), for: UIControlState.highlighted)
            btn.sizeToFit()
        }
        
        self.init(customView:btn);
    }
}
